import 'package:flutter/material.dart';
import 'package:hm_pda_app/config/http_request.dart';
import 'package:hm_pda_app/components/loading_overlay.dart';

class StockingAndWarehousingPage extends StatefulWidget {
  const StockingAndWarehousingPage({super.key});
  @override
  State<StockingAndWarehousingPage> createState() =>
      _StockingAndWarehousingPageState();
}

class _StockingAndWarehousingPageState
    extends State<StockingAndWarehousingPage> {
  final _formKey = GlobalKey<FormState>(); // 表单Key
  final GlobalKey<_StockingAndWarehousingPageState> formKey =
      GlobalKey<_StockingAndWarehousingPageState>();
  // controller
  final _qualityInspectionController = TextEditingController();
  final _skuController = TextEditingController();
  final _warehouseController = TextEditingController();
  final _numController = TextEditingController();
  final _qualityInspectionFocusNode = FocusNode();
  final _skuFocusNode = FocusNode();
  final _wareHouseFocusNode = FocusNode();
  final _numFocusNode = FocusNode();
  // 定义一个变量
  SkuInfoItem? _skuInfo;

  // 通过收货单获取sku信息
  void _getSkuInfo(BuildContext context) async {
    try {
      LoadingOverlay.show(context);
      final response = await HttpUtil.post(
        '/storage/putOnSaleOperate/getLastOrder',
        data: {
          'receiveGoodsNo': _qualityInspectionController.text,
          'skuCode': _skuController.text,
          'whetherLastFinishOrder': false,
        },
      );
      if (response.data != null) {
        final dataMap = response.data as Map<String, dynamic>;
        if (dataMap['id'] == null) {
          print('上架信息---$response');
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(
              content: Text('暂无数据，请输入正确单号或sku编码'),
              duration: Duration(seconds: 3),
            ),
          );
          return;
        }
        setState(() {
          _skuInfo = SkuInfoItem.formJson(dataMap);
          _qualityInspectionController.text = _skuInfo?.receiveGoodsNo ?? '';
          _skuController.text = _skuInfo?.skuCode ?? '';

          _warehouseController.text =
              _skuInfo?.putOnSaleStorageLocationName ?? '';
          // _numController.text = _skuInfo?.expectPutOnSaleNum.toString() ?? '';
        });
        _numFocusNode.requestFocus();
      }
    } catch (e) {
      print(e);
    } finally {
      LoadingOverlay.hide();
    }
  }

  // 清除
  void _resetForm() {
    _qualityInspectionController.clear();
    _skuController.clear();
    _warehouseController.clear();
    _numController.clear();
    setState(() {
      _skuInfo = SkuInfoItem(
        id: '',
        putOnSaleNo: '',
        putOnSaleUserName: '',
        receiveGoodsUserName: '',
        receiveGoodsNo: '',
        skuCode: '',
        putOnSaleStorageLocationName: '',
        actualPutOnSaleNum: 0,
        expectPutOnSaleNum: 0,
        alreadyPutOnSaleNum: 0,
        recommendPutOnSaleStorageLocationName: '',
      );
    });
  }

  // 提交
  void _submitForm(BuildContext context) async {
    try {
      if (!_formKey.currentState!.validate()) {
        print('上架信息校验');
        return;
      }
      LoadingOverlay.show(context);
      final response = await HttpUtil.post(
        '/storage/putOnSaleOperate/commit',
        data: {
          'id': _skuInfo?.id,
          'putOnSaleStorageWarehouseId': _skuInfo?.putOnSaleWarehouseId,
          'putOnSaleStorageLocationName':
              _skuInfo?.putOnSaleStorageLocationName,
          'actualPutOnSaleNum': _numController.text,
        },
      );
      print('上架信息---$response');
      if (response.code != 200) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text('提交报错：${response.message}'),
            duration: Duration(seconds: 3),
          ),
        );

        // 清空表单
      } else {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text('提交成功'), duration: Duration(seconds: 3)),
        );
        _qualityInspectionFocusNode.requestFocus();
      }
    } catch (e) {
      print(e);
    } finally {
      LoadingOverlay.hide();
    }
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _skuInfo = SkuInfoItem(
      id: '',
      putOnSaleNo: '',
      putOnSaleUserName: '',
      receiveGoodsUserName: '',
      receiveGoodsNo: '',
      skuCode: '',
      putOnSaleStorageLocationName: '',
      actualPutOnSaleNum: 0,
      expectPutOnSaleNum: 0,
      alreadyPutOnSaleNum: 0,
      recommendPutOnSaleStorageLocationName: '',
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('上架入库')),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(1),
        child: Form(
          key: _formKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              // 收货单号
              Row(
                children: [
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '上架单：${_skuInfo?.putOnSaleNo}',
                        isRequired: false,
                      ),
                    ),
                  ),
                ],
              ),
              // SizedBox(height: 5),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '上架员：${_skuInfo?.putOnSaleUserName}',
                        isRequired: false,
                      ),
                    ),
                  ),
                ],
              ),
              // SizedBox(height: 5),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel('收货单', isRequired: true),
                    ),
                  ),
                  Expanded(
                    flex: 4,
                    child: Align(
                      alignment: Alignment.center,
                      child: TextFormField(
                        controller: _qualityInspectionController,
                        decoration: _buildInputDecoration(
                          hintText: '收货单',
                          controller: _qualityInspectionController,
                          suffixIcon: ValueListenableBuilder<TextEditingValue>(
                            valueListenable: _qualityInspectionController,
                            builder: (context, value, child) {
                              return value.text.isEmpty
                                  ? SizedBox.shrink()
                                  : IconButton(
                                      icon: Icon(Icons.clear, size: 20),
                                      onPressed: () {
                                        _qualityInspectionController.clear();
                                      },
                                    );
                            },
                          ),
                        ),
                        focusNode: _qualityInspectionFocusNode,
                        onFieldSubmitted: (value) {
                          if (value.isEmpty) {
                            ScaffoldMessenger.of(context).showSnackBar(
                              SnackBar(
                                content: Text('请输入收货单'),
                                duration: Duration(seconds: 3),
                              ),
                            );

                            return;
                          }
                          _getSkuInfo(context);
                          //  _getInfoRequest();
                          print('回车执行');
                        },
                      ),
                    ),
                  ),
                  // 按钮部分
                  Expanded(
                    flex: 1,
                    child: Align(
                      alignment: Alignment.centerRight,
                      child: ElevatedButton(
                        onPressed: () {
                          if (_qualityInspectionController.text.isEmpty) {
                            ScaffoldMessenger.of(context).showSnackBar(
                              SnackBar(
                                content: Text('请输入收货单'),
                                duration: Duration(seconds: 3),
                              ),
                            );

                            return;
                          }
                          _getSkuInfo(context);
                        },
                        style: ElevatedButton.styleFrom(
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(2),
                          ),
                          padding: EdgeInsets.all(12),
                          minimumSize: Size(0, 0),
                          backgroundColor: Colors.blue,
                          foregroundColor: Colors.white,
                          tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                        ),

                        child: Text('查询'),
                      ),
                    ),
                  ),
                ],
              ),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '收货员：${_skuInfo?.receiveGoodsUserName}',
                        isRequired: false,
                      ),
                    ),
                  ),
                ],
              ),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),

              Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel('SKU编码', isRequired: true),
                    ),
                  ),
                  Expanded(
                    flex: 4,
                    child: Align(
                      alignment: Alignment.topLeft,
                      child: TextFormField(
                        controller: _skuController,
                        validator: (value) {
                          if (value == null || value.isEmpty) {
                            return '请输入SKU编码';
                          }

                          return null; // 返回 null 表示验证通过
                        },
                        decoration: _buildInputDecoration(
                          hintText: '请输入SKU编码',
                          controller: _skuController,
                          suffixIcon: ValueListenableBuilder<TextEditingValue>(
                            valueListenable: _skuController,
                            builder: (context, value, child) {
                              return value.text.isEmpty
                                  ? SizedBox.shrink()
                                  : IconButton(
                                      icon: Icon(Icons.clear, size: 20),
                                      onPressed: () {
                                        _skuController.clear();
                                      },
                                    );
                            },
                          ),
                        ),
                        focusNode: _skuFocusNode,
                        onFieldSubmitted: (value) {
                          //  _getInfoRequest();
                          if (value.isEmpty) {
                            ScaffoldMessenger.of(context).showSnackBar(
                              SnackBar(
                                content: Text('请输入SKU编码'),
                                duration: Duration(seconds: 3),
                              ),
                            );

                            return;
                          }
                          _getSkuInfo(context);
                        },
                      ),
                    ),
                  ),
                  // 按钮部分
                  Expanded(
                    flex: 1,
                    child: Align(
                      alignment: Alignment.centerRight,
                      child: ElevatedButton(
                        onPressed: () {
                          if (_numController.text.isEmpty) {
                            ScaffoldMessenger.of(context).showSnackBar(
                              SnackBar(
                                content: Text('请输入SKU'),
                                duration: Duration(seconds: 3),
                              ),
                            );

                            return;
                          }
                          _getSkuInfo(context);
                        },
                        style: ElevatedButton.styleFrom(
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(2),
                          ),
                          padding: EdgeInsets.all(12),
                          minimumSize: Size(0, 0),
                          backgroundColor: Colors.blue,
                          foregroundColor: Colors.white,
                          tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                        ),

                        child: Text('查询'),
                      ),
                    ),
                  ),
                ],
              ),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel('上架库位', isRequired: true),
                    ),
                  ),
                  Expanded(
                    flex: 4,
                    child: Align(
                      alignment: Alignment.center,
                      child: TextFormField(
                        controller: _warehouseController,
                        validator: (value) {
                          if (value == null || value.isEmpty) {
                            return '请输入上架库位';
                          }

                          return null; // 返回 null 表示验证通过
                        },
                        decoration: _buildInputDecoration(
                          hintText: '上架库位',
                          controller: _warehouseController,
                          suffixIcon: ValueListenableBuilder<TextEditingValue>(
                            valueListenable: _warehouseController,
                            builder: (context, value, child) {
                              return value.text.isEmpty
                                  ? SizedBox.shrink()
                                  : IconButton(
                                      icon: Icon(Icons.clear, size: 20),
                                      onPressed: () {
                                        _warehouseController.clear();
                                      },
                                    );
                            },
                          ),
                        ),
                        focusNode: _wareHouseFocusNode,
                        onFieldSubmitted: (value) {
                          //  _getInfoRequest();
                          print('回车执行');
                        },
                      ),
                    ),
                  ),
                  // 按钮部分
                  // Expanded(
                  //   flex: 1,
                  //   child: Align(
                  //     alignment: Alignment.centerRight,
                  //     child: ElevatedButton(
                  //       onPressed: () {
                  //         // _getInfoRequest();
                  //       },
                  //       style: ElevatedButton.styleFrom(
                  //         shape: RoundedRectangleBorder(
                  //           borderRadius: BorderRadius.circular(2),
                  //         ),
                  //         padding: EdgeInsets.all(12),
                  //         minimumSize: Size(0, 0),
                  //         backgroundColor: Colors.blue,
                  //         foregroundColor: Colors.white,
                  //         tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                  //       ),

                  //       child: Text('查询'),
                  //     ),
                  //   ),
                  // ),
                ],
              ),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel('上架数量', isRequired: true),
                    ),
                  ),
                  Expanded(
                    flex: 4,
                    child: Align(
                      alignment: Alignment.center,
                      child: TextFormField(
                        controller: _numController,
                        validator: (value) {
                          if (value == null || value.isEmpty) {
                            return '请输入上架数量';
                          }

                          return null; // 返回 null 表示验证通过
                        },
                        decoration: _buildInputDecoration(
                          hintText: '上架数量',
                          controller: _numController,
                          suffixIcon: ValueListenableBuilder<TextEditingValue>(
                            valueListenable: _numController,
                            builder: (context, value, child) {
                              return value.text.isEmpty
                                  ? SizedBox.shrink()
                                  : IconButton(
                                      icon: Icon(Icons.clear, size: 20),
                                      onPressed: () {
                                        _numController.clear();
                                      },
                                    );
                            },
                          ),
                        ),
                        focusNode: _numFocusNode,
                        onFieldSubmitted: (value) {
                          //  _getInfoRequest();
                          print('回车执行');
                        },
                      ),
                    ),
                  ),
                  // 按钮部分
                  // Expanded(
                  //   flex: 1,
                  //   child: Align(
                  //     alignment: Alignment.centerRight,
                  //     child: ElevatedButton(
                  //       onPressed: () {
                  //         // _getInfoRequest();
                  //       },
                  //       style: ElevatedButton.styleFrom(
                  //         shape: RoundedRectangleBorder(
                  //           borderRadius: BorderRadius.circular(2),
                  //         ),
                  //         padding: EdgeInsets.all(12),
                  //         minimumSize: Size(0, 0),
                  //         backgroundColor: Colors.blue,
                  //         foregroundColor: Colors.white,
                  //         tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                  //       ),

                  //       child: Text('查询'),
                  //     ),
                  //   ),
                  // ),
                ],
              ),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child:
                          _skuInfo?.pictureUrl != null &&
                              _skuInfo!.pictureUrl!.isNotEmpty
                          ? GestureDetector(
                              onTap: () {
                                _showImagePreview(
                                  context,
                                  _skuInfo!.pictureUrl!,
                                );
                              },
                              child: Image(
                                image: NetworkImage(_skuInfo!.pictureUrl!),
                                width: 100,
                                height: 100,
                                errorBuilder: (context, error, stackTrace) {
                                  return Container(
                                    width: 100,
                                    height: 100,
                                    color: Colors.grey[200],
                                    child: Icon(
                                      Icons.image_not_supported,
                                      size: 50,
                                      color: Colors.grey[400],
                                    ),
                                  );
                                },
                              ),
                            )
                          : Container(
                              width: 100,
                              height: 100,
                              color: Colors.grey[200],
                              child: Icon(
                                Icons.image,
                                size: 50,
                                color: Colors.grey[400],
                              ),
                            ),
                    ),
                  ),
                  Expanded(
                    flex: 4,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Expanded(
                                flex: 1,
                                child: Align(
                                  alignment: Alignment.centerLeft,
                                  child: _buildLabel(
                                    '应上架数量:${_skuInfo?.expectPutOnSaleNum}',
                                    isRequired: false,
                                  ),
                                ),
                              ),
                            ],
                          ),
                          const Divider(
                            height: 2, // 容器总高度2像素
                            thickness: 1, // 分割线厚度5像素
                            indent: 0, // 左侧缩进20像素
                            endIndent: 0, // 右侧无缩进
                            color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
                          ),
                          Row(
                            children: [
                              Expanded(
                                flex: 1,
                                child: Align(
                                  alignment: Alignment.centerLeft,
                                  child: _buildLabel(
                                    '已上架数量:${_skuInfo?.alreadyPutOnSaleNum}',
                                    isRequired: false,
                                  ),
                                ),
                              ),
                            ],
                          ),
                          const Divider(
                            height: 2, // 容器总高度2像素
                            thickness: 1, // 分割线厚度5像素
                            indent: 0, // 左侧缩进20像素
                            endIndent: 0, // 右侧无缩进
                            color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
                          ),
                          Row(
                            children: [
                              Expanded(
                                flex: 1,
                                child: Align(
                                  alignment: Alignment.centerLeft,
                                  child: _buildLabel(
                                    '推荐库位:${_skuInfo?.recommendPutOnSaleStorageLocationName}',
                                    isRequired: false,
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
            ],
          ),
        ),
      ),
      bottomNavigationBar: DecoratedBox(
        decoration: BoxDecoration(color: const Color.fromARGB(255, 77, 76, 76)),
        child: SizedBox(
          width: double.infinity,
          height: 50,
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16.0),
            child: Row(
              children: [
                Expanded(
                  child: SizedBox(
                    height: 40,
                    child: OutlinedButton(
                      onPressed: () {
                        // 取消操作，重置表单
                        _resetForm();
                        // final formState = context
                        //     .findAncestorStateOfType<IncomingGoodsFormState>();
                        // formState?._resetForm();
                      },
                      style: OutlinedButton.styleFrom(
                        foregroundColor: Colors.white,
                        backgroundColor: Colors.grey[600],
                        side: BorderSide.none,
                        textStyle: const TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.w500,
                        ),
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(12),
                        ),
                        elevation: 1,
                      ),
                      child: const Text('清除'),
                    ),
                  ),
                ),
                const SizedBox(width: 12),

                Expanded(
                  child: (_skuInfo?.id == null || _skuInfo!.id!.isEmpty)
                      ? Text('')
                      : SizedBox(
                          height: 40,
                          child: ElevatedButton(
                            onPressed: () {
                              _submitForm(context);
                            },
                            style: ElevatedButton.styleFrom(
                              backgroundColor: Colors.blue[600],
                              foregroundColor: Colors.white,
                              textStyle: const TextStyle(
                                fontSize: 16,
                                fontWeight: FontWeight.w600,
                              ),
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(12),
                              ),
                              elevation: 3,
                              // shadowColor: Colors.blue.withOpacity(0.3),
                            ),
                            child: const Text('提交'),
                          ),
                        ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

// 构建标签文本
Widget _buildLabel(String text, {bool isRequired = false}) {
  return SizedBox(
    // width: 200,
    child: Padding(
      padding: EdgeInsets.symmetric(horizontal: 2),
      child: Text(
        text,
        style: TextStyle(
          fontWeight: FontWeight.w500,
          fontSize: 16,
          color: isRequired ? Colors.red : Colors.grey[700],
        ),
      ),
    ),
  );
}

void _showImagePreview(BuildContext context, String imageUrl) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return Dialog(
        backgroundColor: Colors.transparent,
        child: Stack(
          children: [
            Center(
              child: InteractiveViewer(
                panEnabled: true, // 允许拖拽
                boundaryMargin: EdgeInsets.all(20),
                minScale: 0.1,
                maxScale: 6.0,
                child: SizedBox(
                  width: MediaQuery.of(context).size.width * 0.9,
                  child: Image.network(
                    imageUrl,
                    fit: BoxFit.contain,
                    errorBuilder: (context, error, stackTrace) {
                      return Container(
                        padding: EdgeInsets.all(20),
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Icon(Icons.error, size: 50, color: Colors.white),
                            SizedBox(height: 10),
                            Text(
                              '图片加载失败',
                              style: TextStyle(color: Colors.white),
                            ),
                          ],
                        ),
                      );
                    },
                  ),
                ),
              ),
            ),
            Positioned(
              top: 40,
              right: 20,
              child: GestureDetector(
                onTap: () => Navigator.of(context).pop(),
                child: Container(
                  width: 40,
                  height: 40,
                  decoration: BoxDecoration(
                    color: Colors.black54,
                    shape: BoxShape.circle,
                  ),
                  child: Icon(Icons.close, color: Colors.white, size: 24),
                ),
              ),
            ),
          ],
        ),
      );
    },
  );
}

// 构建输入框装饰
InputDecoration _buildInputDecoration({
  required String hintText,
  required TextEditingController controller,
  Widget? suffixIcon,
}) {
  print('controller ${controller.text}');
  return InputDecoration(
    hintText: hintText,
    contentPadding: EdgeInsets.zero, // 设置上下左右内边距都为0
    // prefixIcon: Icon(prefixIcon, color: Colors.grey[600]),
    suffixIcon: suffixIcon,
    hintStyle: TextStyle(color: Colors.grey[500]),
    // isDense: true 属性用于减少输入框的垂直高度，使其更紧凑
    // 当设置为 true 时，会减少内边距，让输入框看起来更小更密集
    // 适用于需要节省空间或创建更紧凑布局的场景
    // isDense: true,
    filled: true,
    fillColor: Colors.grey[50],

    // suffixIcon: controller.text.isNotEmpty
    //             ? IconButton(
    //                 icon: Icon(Icons.clear, size: 20),
    //                 onPressed: () {
    //                   controller.clear();
    //                   // 需要通知父组件状态更新
    //                   if (mounted) {
    //                     setState(() {});
    //                   }
    //                 },
    //               )
    //             : null,
    border: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.grey[300]!),
    ),
    enabledBorder: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.grey[300]!),
    ),
    focusedBorder: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.blue, width: 2),
    ),
    errorBorder: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.red),
    ),
    focusedErrorBorder: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.red, width: 2),
    ),
  );
}

// sku详情类
class SkuInfoItem {
  final String? id;
  final String? putOnSaleNo;
  final String? putOnSaleUserName;
  final String? receiveGoodsUserName;
  final String? receiveGoodsNo;
  final String? skuCode;
  final String? putOnSaleStorageLocationName;
  final num? actualPutOnSaleNum;
  final num? expectPutOnSaleNum;
  final num? alreadyPutOnSaleNum;
  final String? recommendPutOnSaleStorageLocationName;
  final String? pictureUrl;
  final String? putOnSaleWarehouseId;
  SkuInfoItem({
    this.id,
    this.putOnSaleNo,
    this.putOnSaleUserName,
    this.receiveGoodsUserName,
    this.receiveGoodsNo,
    this.skuCode,
    this.putOnSaleStorageLocationName,
    this.actualPutOnSaleNum,
    this.expectPutOnSaleNum,
    this.alreadyPutOnSaleNum,
    this.recommendPutOnSaleStorageLocationName,
    this.pictureUrl,
    this.putOnSaleWarehouseId,
  });
  factory SkuInfoItem.formJson(Map<String, dynamic> json) {
    return SkuInfoItem(
      id: json['id'],
      putOnSaleNo: json['putOnSaleNo'],
      putOnSaleUserName: json['putOnSaleUserName'],
      receiveGoodsUserName: json['receiveGoodsUserName'],
      receiveGoodsNo: json['receiveGoodsNo'],
      skuCode: json['skuCode'],
      putOnSaleStorageLocationName: json['putOnSaleStorageLocationName'],
      actualPutOnSaleNum: json['actualPutOnSaleNum'],
      expectPutOnSaleNum: json['expectPutOnSaleNum'],
      alreadyPutOnSaleNum: json['alreadyPutOnSaleNum'],
      recommendPutOnSaleStorageLocationName:
          json['recommendPutOnSaleStorageLocationName'],
      pictureUrl: json['pictureUrl'],
      putOnSaleWarehouseId: json['putOnSaleWarehouseId'],
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'putOnSaleNo': putOnSaleNo,
      'putOnSaleUserName': putOnSaleUserName,
      'receiveGoodsUserName': receiveGoodsUserName,
      'receiveGoodsNo': receiveGoodsNo,
      'skuCode': skuCode,
      'putOnSaleStorageLocationName': putOnSaleStorageLocationName,
      'actualPutOnSaleNum': actualPutOnSaleNum,
      'expectPutOnSaleNum': expectPutOnSaleNum,
      'alreadyPutOnSaleNum': alreadyPutOnSaleNum,
      'recommendPutOnSaleStorageLocationName':
          recommendPutOnSaleStorageLocationName,
      'putOnSaleWarehouseId': putOnSaleWarehouseId,
    };
  }
}
